<?php

namespace StudyBuddy;

use StudyBuddy\Interfaces\Indexer;

/**
 *
 * This class is responsible for instantiating and
 * returning the search provider object
 * It will use the best available search provider
 * and is guaranteed to return object that implements
 * \StudyBuddy\Interfaces\Search interface
 *
 */
class IndexerFactory {

    public static function factory(Registry $oRegistry) {

        if (extension_loaded('pdo_mysql')) {
            $o = new \StudyBuddy\Modules\Search\IndexerMySQL($oRegistry);
        }



        if (!isset($o)) {
            e('Search feature is not implemented because no search providers are defined');
            return new Stub();
        }

        if (!($o instanceof Indexer)) {
            throw new \StudyBuddy\DevException('Indexer class ' . get_class($o) . ' does not implement Indexer interface');
        }


        return $o;
    }

}
